
import java.util.StringTokenizer;
import java.util.Vector;

class P630 {

	public static void main(String[] args) {
		int cases = Integer.parseInt(readLn());
		for (int k = 0; k < cases; k++) {
			readLn();
			process();
			if (k + 1 != cases) System.out.println();
		}
	}

	private static void process() {
		int setLength = Integer.parseInt(readLn());
		String[] set = new String[setLength];
		for (int k = 0; k < setLength; k++) {
			set[k] = readLn();
		}
		String line = readLn();
		while (line != null && !line.trim().equals("END")) {
			System.out.println("Anagrams for: " + line);
			int counter = 1;
			for (int i = 0; i < setLength; i++) {
				if (isAnagramSimple(line, set[i])) {
					String no = counter + "";
					for (int j = no.length(); j < 3; j++) {
						no = " " + no;
					}
					System.out.println(no + ") " + set[i]);
					counter++;
				}
			}
			if (counter == 1) {
				System.out.println("No anagrams for: " + line);
			}
			line = readLn();
		}
	}

	private static boolean isAnagram(String phrase1, String phrase2) {
		StringTokenizer st1 = new StringTokenizer(phrase1.trim());
		String s1 = "";
		while (st1.hasMoreTokens()) {
			s1 += st1.nextToken();
		}

		StringTokenizer st2 = new StringTokenizer(phrase2.trim());
		String s2 = "";
		while (st2.hasMoreTokens()) {
			s2 += st2.nextToken();
		}

		return isAnagramSimple(s1, s2);
	}

	private static boolean isAnagramSimple(String x1, String x2) {
		if (x1.length() != x2.length()) {
			return false;
		}
		int[] xA1 = new int[26];
		int[] xA2 = new int[26];

		for (int k = 0; k < x1.length(); k++) {
			char c1 = x1.charAt(k);
			c1 = Character.toLowerCase(c1);
			char c2 = x2.charAt(k);
			c2 = Character.toLowerCase(c2);
			xA1[((int) c1) - 'a']++;
			xA2[((int) c2) - 'a']++;
		}
		return analise(xA1, xA2);
	}

	private static boolean analise(int[] xa1, int[] xa2) {
		for (int k = 0; k < 26; k++) {
			if (xa1[k] != xa2[k]) {
				return false;
			}
		}
		return true;
	}

	private static void sort(Vector words) {
		quickSortWords(words, 0, words.size() - 1);
	}

	private static void quickSortWords(Vector vector, int i, int j) {
		if (i < j) {
			int q = partition(vector, i, j);
			quickSortWords(vector, i, q - 1);
			quickSortWords(vector, q + 1, j);
		}
	}

	private static int partition(Vector vector, int p, int r) {
		String x = (String) vector.elementAt(r);
		int i = p - 1;
		for (int j = p; j < r; j++) {
			if (((String) vector.elementAt(j)).compareTo(x) <= 0) {
				i = i + 1;
				swap(vector, i, j);
			}
		}
		swap(vector, i + 1, r);
		return i + 1;
	}

	private static void swap(Vector vector, int i, int r) {
		String aux = (String) vector.elementAt(i);
		vector.setElementAt(vector.elementAt(r), i);
		vector.setElementAt(aux, r);
	}

	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuffer buffer = new StringBuffer();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString());
	}

}